/*****************************************************************************/
// The realization of insetion sort of descending
// Input an array of numbers.
// Output the asendingly sorted array.
/*****************************************************************************/

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <strstream>
using namespace std;

/*
bool isNum ( string s ) {
	for ( string::iterator is = s.begin(); is != s.end(); ++is ) {
		if ( ! isdigit(*is) )
			return 0;
	}
	return 1;
}*/

void Insertion_sort ( vector<int> & unsorted ) {
	int key;
	int tmp;
	// to avoid the downward overflow of ivec1, preprocess the first 2 data
	tmp = unsorted[0];
	unsorted[0] = unsorted[0] <= unsorted[1] ? unsorted[1] : unsorted[0];
	unsorted[1] = unsorted[0] <= unsorted[1] ? tmp : unsorted[1];
	// sort the 3..n data
	for ( vector<int>::iterator ivec = unsorted.begin() + 2; ivec != unsorted.end(); ++ivec ) {
		key = *ivec;
		vector<int>::iterator ivec1 = ivec - 1;
		while ( ivec1 != unsorted.begin() && *ivec1 < key ) {
			*(ivec1+1) = *ivec1;
			--ivec1;
		}
		*(ivec1+1) = key;
	}
}

int main(){
	/* code */
	vector<int> sorted;
	int buffer;
	cout << "plese input an array of numbers." << endl;
	while ( cin >> buffer ) {
		//strstream ss;
		//string s;
		//ss << buffer;
		//ss >> s;
		//if ( isNum(s) )
		sorted.push_back(buffer);
		/*for ( vector<int>::iterator ivec_s = sorted.begin(); ivec_s != sorted.end(); ++ivec_s)
			cout << *ivec_s << '/t';*/
		/*else {
			cout << "The array you input is illegal!" << endl;
			return 0;
		}*/
	}
	Insertion_sort(sorted);
	for ( vector<int>::iterator ivec_s = sorted.begin(); ivec_s != sorted.end(); ++ivec_s)
		cout << *ivec_s << '\t';
	cout << endl;
	return 0;
}